package com.darly.book.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;

import com.darly.book.BookController;
import com.darly.book.R;
import com.darly.book.event.RecommendBookEvent;
import com.darly.book.utils.Constant;
import com.darly.book.utils.SharedPreUtils;

public class SexChooseDialog extends Dialog implements View.OnClickListener {
    ImageView mIvClose;
    Button mBtnBoy;
    Button mBtnGirl;


    public SexChooseDialog(Context context) {
        super(context, R.style.CommonDialog);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_sex_choose);
        mIvClose = findViewById(R.id.choose_iv_close);
        mIvClose.setOnClickListener(this);
        mBtnBoy = findViewById(R.id.choose_btn_boy);
        mBtnBoy.setOnClickListener(this);
        mBtnGirl = findViewById(R.id.choose_btn_girl);
        mBtnGirl.setOnClickListener(this);
        setUpWindow();
    }

    private void setUpWindow() {
        WindowManager.LayoutParams lp = getWindow().getAttributes();
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        lp.horizontalMargin = 0;
    }


    @Override
    public void onDetachedFromWindow() {
        super.onDetachedFromWindow();
    }

    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.choose_btn_boy) {
            //保存到SharePreference中
            SharedPreUtils.getInstance()
                    .putString(Constant.SHARED_SEX, Constant.SEX_BOY);
            BookController.getInstance().post(new RecommendBookEvent("male"));
        } else if (view.getId() == R.id.choose_btn_girl) {
//保存到SharePreference中
            SharedPreUtils.getInstance()
                    .putString(Constant.SHARED_SEX, Constant.SEX_GIRL);
            BookController.getInstance().post(new RecommendBookEvent("female"));
        }
        dismiss();
    }
}
